<%--
 *  File:    OrgGroupMap.jsp
 *  @Author: Jianni 
 *  Date:    2002/02/28
 *
 *  Copyright (C) 2000 - 2001 Oval Technologies, Inc.
 *  All rights reserved. 
 *
 *  This software is the confidential and proprietary information of Oval 
 *  Technologies, Inc. ("Confidential Information").  You shall not
 *  disclose such Confidential Information and shall use it only in
 *  accordance with the terms of the license agreement you entered into
 *  with Oval.
--%>


<%@ include file="/inc/SessionTimeout.inc"%>
<%@ page language="java" %>     
<%@ page import="java.util.*" %>
<%@ page import="org.apache.log4j.Category" %>

<%@ page contentType = "text/html;charset=UTF-8" %>
<%@ taglib uri="/WEB-INF/PageFlow.tld" prefix="PageFlow" %>
<%@ taglib uri="/WEB-INF/struts-logic.tld" prefix="logic" %>
<%@ taglib uri="/WEB-INF/oval-tag.tld" prefix="oval" %>
<%@ taglib uri="/WEB-INF/custom.tld" prefix="custom" %>


<% //--------------------------------------  setting logger --%>
<%
  	Category cat = Category.getInstance("jsp.OrgGroupMap");  
%>

<% //--------------------------------------  variant and initialization --%>
<%
  	String strModuleName = "OGM";
	String privilegeCode = "10107,L105";
%>
  

  
<%
  	HashMap userInfo = (HashMap)session.getAttribute("userinfo");    
  	String orgrelationdetailid = null;
  	String targetorggroupid = null;
%>

<% //--------------------------------------  include files list --%>
<%@ include file="/inc/Security.inc" %>
<%@ include file="/inc/PageDefault.inc" %>
<%@ include file="/inc/LocationDefault.inc" %>

<html>
<head>
<title>orggroupmap</title>
<PageFlow:CheckPageFlow pageName="orggroupmap"/>
<%@ include file="/inc/InitEdit.inc" %>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link rel="stylesheet" href="../../css/<%= strLanguageCode %>/main.css" type="text/css">
<script language="JavaScript" src="../../css/<%= strLanguageCode %>/script.js"></script>
<script language="JavaScript" src="../../js/FuncLib.js"></script>

<% //--------------------------------------  output variant from pageflow --%>
<%
  	Vector orgGroupMapInfo = (Vector)pageContext.getAttribute("orggroupmapinfo");
  	Vector relationdetails = (Vector)pageContext.getAttribute("relationdetails");
  	if(relationdetails==null)
  		relationdetails = new Vector();
  	Vector targetgroups = (Vector)pageContext.getAttribute("targetgroups");
  	if(targetgroups==null)
  		targetgroups = new Vector();
  		
  	if(orgGroupMapInfo == null)
  	{
    	orgGroupMapInfo = new Vector();
  	}
  	cat.debug("The orgGroupMapInfo is :" + orgGroupMapInfo);
  	String sourceOrgGroupId = request.getParameter("sourceorggroupid");
  	if(sourceOrgGroupId==null)
  		sourceOrgGroupId = ((Integer)pageContext.getAttribute("sourceorggroupid")).toString();
  		
  	HashMap relationdetailinfo = (HashMap)pageContext.getAttribute("relationdetailinfo");
  	
  	if(relationdetailinfo!=null)
  	{
  		orgrelationdetailid = ((Integer)relationdetailinfo.get("orgrelationdetailid")).toString();
  		targetorggroupid = (relationdetailinfo.get("targetorggroupid")==null ? "" : ((Integer)relationdetailinfo.get("targetorggroupid")).toString());
  	}	
  	else
  		relationdetailinfo = new HashMap();
  	
  	
%>
<script>
function page_remove()
{
  <%--[SCRIPT]  var isSelectItem = false;  [SCRIPT]--%>
	<%--[SCRIPT]  var checkitem = document.all.item('removeorggroupmaps');  [SCRIPT]--%>
	<%--[SCRIPT]  for(var i = 0; i<checkitem.length;i++)  [SCRIPT]--%>
	<%--[SCRIPT]  {   [SCRIPT]--%>
	<%--[SCRIPT]  	if(checkitem[i].checked)  [SCRIPT]--%>
	<%--[SCRIPT]      {  [SCRIPT]--%>
	<%--[SCRIPT]      	isSelectItem = true;  [SCRIPT]--%>
	<%--[SCRIPT]        	break;  [SCRIPT]--%>
	<%--[SCRIPT]      }  [SCRIPT]--%>
	<%--[SCRIPT]  }  [SCRIPT]--%>
	<%--[SCRIPT]  if(!isSelectItem)  [SCRIPT]--%>
	<%--[SCRIPT]  	return;  [SCRIPT]--%>
	if(nullChecked(orggroupmapform.removeorggroupmaps))
	{
	  alert("<%=message.getMessageDesc("PLEASE_SELECT")%>");
	  return;
	}
	if(document.orggroupmapform.targetorgid.value=="")
		document.orggroupmapform.targetorgid.disabled=true;
	if(document.orggroupmapform.orgrelationdetailid.value=="")	
		document.orggroupmapform.orgrelationdetailid.disabled=true;
  	document.orggroupmapform.actionname.value = "remove";
  	isRunning = true;
  	document.orggroupmapform.submit();
}

function page_add()
{
	var val = document.orggroupmapform.orgrelationdetailid0.value;
	if(val==-1)
		return;
	if(orggroupmapform.targetorggroupid.value=="-1")
		return;	
	var v = val.split("^");
	document.orggroupmapform.orgrelationdetailid.value=v[0];
	document.orggroupmapform.targetorgid.value=v[1];
  document.orggroupmapform.actionname.value = "add";
  isRunning = true;
  document.orggroupmapform.submit();
}
function page_change()
{
	var val = document.orggroupmapform.orgrelationdetailid0.value;
	if(val==-1)
		return;
	var v = val.split("^");
	document.orggroupmapform.orgrelationdetailid.value=v[0];
	document.orggroupmapform.targetorgid.value=v[1];
	document.orggroupmapform.action="OrgGroupMap.jsp?<%= OvalTools.randomURL() %>";
	document.orggroupmapform.submit();
}
</script>
</head>
<body>

	<% //--------------------------------------  hidden form variant --%>
	<form name="orggroupmapform" method="post" action="../../Dispatcher">
    <input type="hidden" name="pagename" value="orggroupmap">
    <input type="hidden" name="actionname">   
    <input type="hidden" name="sourceorggroupid" value="<%=JspHelper.filterNull( sourceOrgGroupId )%>">   
    <input type="hidden" name="languagecode" value="<%= strLanguageCode %>">   
    <input type="hidden" name="orgid" value="<%=JspHelper.filterNull( userInfo.get("orgid") )%>">   
    <input type="hidden" name="targetorgid" >   
    <input type="hidden" name="orgrelationdetailid" >   
    
	<table width="100%" cellspacing="0" border="0" cellpadding="0">
  	<tr> 
    	<td> 
      		<table width="100%" border="1" cellpadding="0" bordercolorlight="#999999" bordercolordark="#FFFFFF" cellspacing="0" align="center">
          	<tr class="deepblue-left"> 
            	<td width="22" class="title_center">&nbsp;</td>
            	<td class="title_center" width="250"><%= label.getLabelName("L_Vendor") %></td>
            	<td class="title_center" width="200"><%= label.getLabelName("L_VendorGroupName") %></td>
            	<td class="title_center"><%= label.getLabelName("L_VendorGroupDesc") %></td>
          	</tr>
          	
          	<%
            	int i = 0;
            	String strClassType = new String("");   
            	boolean bHasChecked = false;
          	%>
          	<logic:iterate id="is" collection="<%= orgGroupMapInfo %>">                      
          	<%
            	HashMap isMap = (HashMap)pageContext.getAttribute("is"); 
            	String strIsChecked = new String("");
            	if(i%2 == 1)
            	{
              		strClassType = "td-listrom";
            	}else{                    
              		strClassType = "none";
            	}
            	if(!bHasChecked)
            	{
              		strIsChecked = "Checked";                       
              		bHasChecked = true;            
            	}                
            	i++;     
           	%>
          	<tr onMouseOver="this.className='tr-over'" onMouseOut="this.className='<%=JspHelper.filterNull( strClassType )%>'"  class="<%=JspHelper.filterNull( strClassType )%>"> 
            	<td> 
            	    
              		<input type="checkbox" name="removeorggroupmaps" value="<%=JspHelper.filterNull( isMap.get("orggroupmapid") )%>" class="normalradio">
            	</td>
            	<td>&nbsp;<%=JspHelper.filterNull( isMap.get("targetorgname") )%></td>
            	<td>&nbsp;<%=JspHelper.filterNull( isMap.get("groupname") )%></td>
            	<td>&nbsp;<%=JspHelper.filterNull( isMap.get("groupdesc") )%></td>
          	</tr>
          	</logic:iterate>         
          	
          	<tr> 
          	<TD class=title_center width=22>&nbsp;</TD>
            	<td width="250"><%= label.getLabelName("L_Vendor") + label.getLabelName("L_Colon") %>
            		<select name="orgrelationdetailid0" onchange="javascript:page_change()">
            		<option value="-1">------</option>
              <logic:iterate id="rs" collection="<%= relationdetails %>">
            <% 
              HashMap mapTypes = (HashMap)pageContext.getAttribute("rs"); 
              String strSelect = "";
              String tempValue = ((Integer)mapTypes.get("orgrelationdetailid")).toString();
              if(tempValue.equalsIgnoreCase(orgrelationdetailid))
              {
                strSelect = "Selected";
              }                              
            %>
              <option <%=JspHelper.filterNull( strSelect )%>  value = "<%=JspHelper.filterNull( (Integer)mapTypes.get("orgrelationdetailid"))%>^<%=JspHelper.filterNull( (Integer)mapTypes.get("targetorgid"))%>">
              <%=JspHelper.filterNull( mapTypes.get("targetorgname") )%>
              </option>
            </logic:iterate> 
            </select>
            </TD>
              	<TD width=200>	
              		<%= label.getLabelName("L_Group") + label.getLabelName("L_Colon") %>
              		
              		<select name="targetorggroupid">
              		<%if(targetgroups.size()==0){%>
              		<option value="-1">------</option>
              		<%}%>
              <logic:iterate id="ts" collection="<%= targetgroups %>">
            <% 
              HashMap mapTypes = (HashMap)pageContext.getAttribute("ts"); 
              String strSelect = "";
              String tempValue = ((Integer)mapTypes.get("orggroupid")).toString();
              if(tempValue.equalsIgnoreCase(targetorggroupid))
              {
                strSelect = "Selected";
              }                              
            %>
              <option <%=JspHelper.filterNull( strSelect )%>  value = "<%=JspHelper.filterNull( (Integer)mapTypes.get("orggroupid"))%>">
              <%=JspHelper.filterNull( mapTypes.get("groupname") )%>
              </option>
            </logic:iterate> 
            </select>
            
            	</td>
            	<TD class=title_center>&nbsp;</TD>
          	</tr>
        	</table>
        	
        	<% //--------------------------------------  page operation button --%>
      		<table width="100%" cellspacing="0" cellpadding="0">
        	<tr> 
          		<td class="summary_top"></td>
        	</tr>
        	<tr> 
          		<td class="td_center">
          			<a onclick="page_add()"><custom:button type="1" label="L_Add" imgsrc="add.gif" border="0" style="width:60"/></a>&nbsp;&nbsp;<a onclick="page_remove()"><custom:button type="1" label="L_Delete" imgsrc="delete.gif" border="0" style="width:60"/></a></td>
        	</tr>
      		</table>
    	</td>
  	</tr>
	</table>

</form>
</body>
</html>


